<?php
include_once 'controller/default.php';
include_once 'connection/connection_database.php';

class tags {

    function Insert($tags) {
        $strQuery = "SELECT tag_name FROM tags WHERE tag_name='{$tags["tagsname"]}'";
        $rs = mysql_query($strQuery) or die(mysql_error());
        $order = mysql_num_rows($rs);
        if($order > 0){
            return false;
        }
        $str = trim(khongdau($tags['tagsname']));
        $link = strtolower(preg_replace('/[^a-z0-9]+/i','-',$str)); 
        $sql = "INSERT INTO tags(tag_name, tag_link) VALUES('{$tags["tagsname"]}', '{$link}')";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
        
    }

    function Delete($tags) {
        $sql = "DELETE FROM tags WHERE tag_id='{$tags["id"]}'";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }
    
    function Update($tags) {
        $str = trim(khongdau($tags['tagsname']));
        $link = strtolower(preg_replace('/[^a-z0-9]+/i','-',$str)); 
        $sql = "UPDATE tags SET tag_name='{$tags["tagsname"]}', tag_link='{$link}' WHERE tag_id='{$tags["id"]}'";
        return mysql_query($sql) or die(mysql_error());
    }

    function FillAll() {
        $sql = "SELECT * FROM tags WHERE tag_status = 1";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }

    function FillOne($tags) {
        $sql = "SELECT * FROM tags WHERE tag_id='{$tags["id"]}'";
        $result = mysql_query($sql) or die(mysql_error());
        return mysql_fetch_array($result);
    }

}

?>
